package user

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	agentClient "gitee.com/liuxuezhan/ar-platform/rpc-client/agentClient/client"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserBindInviteCodeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 会员管理 - 会员层级 - 绑定邀请码
func NewUserBindInviteCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserBindInviteCodeLogic {
	return &UserBindInviteCodeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserBindInviteCodeLogic) UserBindInviteCode(req *types.UserBindInviteCodeRequest) (resp *types.UserBindInviteCodeResponse, err error) {
	rpcReq := &agentClient.AgentBindRequest{
		UserId:     req.UserId,
		InviteCode: req.InviteCode,
	}
	_, err = l.svcCtx.AgentRPC.Bind(l.ctx, rpcReq)
	if err != nil {
		return nil, err
	}
	resp = &types.UserBindInviteCodeResponse{}
	return
}
